package com.xiaoshuidi.cloud.module.contract.controller.admin.contract;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.operatelog.core.annotations.OperateLog;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.signingSubject.AutoSignCallbackReqVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.signingSubject.ContractSignCallbackReqVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.signingSubject.ContractTabletSignCallbackReqVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.signingSubject.SigningSubjectAuthCallbackReqVO;
import com.xiaoshuidi.cloud.module.contract.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.contract.service.contract.ElectronicContractService;
import com.xiaoshuidi.cloud.module.contract.service.contract.SigningSubjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

/**
 * @Description:
 * @author: zhaoyu
 * @date: 2023/5/19
 */
@Slf4j
@Tag(name = "管理后台 - 签约回调")
@RestController
@RequestMapping(ApiConstants.NAME + "/callback")
public class ContractCallbackController {

    @Resource
    private ElectronicContractService electronicContractService;
    @Resource
    private SigningSubjectService signingSubjectService;

    @RequestMapping("/sign")
    @PermitAll
    @Operation(summary = "法大大手动签约的回调", description = "法大手动签约的回调")
    @OperateLog(enable = false)
    public CommonResult<Boolean> receiveFadadaSignCallback(ContractSignCallbackReqVO reqVO) throws Throwable {
        log.info("手动签约法大大回调，回调参数：{}", reqVO);
        electronicContractService.signCallback(reqVO);
        return success(true);
    }


    @RequestMapping("/company-real-name")
    @PermitAll
    @Operation(summary = "法大大企业实名的回调", description = "法大大企业实名的回调")
    @OperateLog(enable = false)
    public CommonResult<Boolean> companyRealNameCallback(SigningSubjectAuthCallbackReqVO reqVO) throws Throwable {
        log.info("企业实名法大大回调，回调参数：{}", reqVO);
        signingSubjectService.authCallback(reqVO);
        return success(true);
    }

    @RequestMapping("/auto-sign")
    @PermitAll
    @Operation(summary = "法大大企业授权自动签约的回调", description = "法大大企业授权自动签约的回调")
    @OperateLog(enable = false)
    public CommonResult<Boolean> autoSignCallback(AutoSignCallbackReqVO reqVO) throws Throwable {
        log.info("授权自动签约法大大回调，回调参数：{}", reqVO);
        signingSubjectService.autoSignCallback(reqVO);
        return success(true);
    }

    @RequestMapping("/sign-security-protocol")
    @PermitAll
    @Operation(summary = "法大大手动签署安全协议的回调", description = "法大手动签署安全协议的回调")
    @OperateLog(enable = false)
    public CommonResult<Boolean> receiveSignSecurityProtocolCallback(ContractSignCallbackReqVO reqVO) throws Throwable {
        log.info("法大大手动签署安全协议的回调，回调参数：{}", reqVO);
        electronicContractService.signSecurityProtocolCallback(reqVO);
        return success(true);
    }


    @PostMapping("/tablet/sign")
    @PermitAll
    @Operation(summary = "手写板乙方手动签约的回调", description = "手写板乙方手动签约的回调")
    @OperateLog(enable = false)
    public CommonResult<Boolean> receiveTabletSignCallback(@RequestBody ContractTabletSignCallbackReqVO reqVO) throws Throwable {
        log.info("手写板乙方手动签约的回调，回调参数：{}", reqVO);
        electronicContractService.tabletSignCallback(reqVO);
        return success(true);
    }
}
